<template>
	<view class="">
		<view class="bg-w pd15">
			<u--form labelPosition="left" :model="model1" :rules="rules" ref="uForm" labelWidth="180rpx">
				<u-form-item label="客户名称" prop="clientName" ref="item1" :required="true">
					<u--input v-model="model1.clientName" border="surround" placeholder="请输入客户名称"></u--input>
				</u-form-item>
				<u-form-item label="客户编号" prop="clientCode" ref="item1" :required="true">
					<u--input v-model="model1.clientCode" border="surround" placeholder="请输入客户编号	" disabled></u--input>
				</u-form-item>
				<u-form-item label="联系人" prop="contactPerson" ref="item1">
					<u--input v-model="model1.contactPerson" border="surround" clearable
						placeholder="请输入联系人"></u--input>
				</u-form-item>
				<u-form-item label="联系电话" prop="contactPhone" ref="item1">
					<u--input v-model="model1.contactPhone" border="surround" placeholder="请输入联系电话"></u--input>
				</u-form-item>
				<u-form-item label="联系地址" prop="contactAddress" ref="item1">
					<u--input v-model="model1.contactAddress" border="surround" placeholder="请输入联系地址"></u--input>
				</u-form-item>
				<u-form-item label="客户生日" prop="clientBirthday" ref="item1" @click="show=true">
					<u--input v-model="model1.clientBirthday" border="surround" placeholder="请输入客户生日"
						disabledColor="#fff" disabled></u--input>
				</u-form-item>
				<u-form-item label="社交账号" prop="socialAccount" ref="item1">
					<u--input v-model="model1.socialAccount" border="surround" placeholder="请输入社交账号"></u--input>
				</u-form-item>
				<u-form-item label="邮箱地址" prop="email" ref="item1">
					<u--input v-model="model1.email" border="surround" placeholder="请输入邮箱地址"></u--input>
				</u-form-item>
				<u-form-item label="开户银行" prop="bankOfDeposit" ref="item1">
					<u--input v-model="model1.bankOfDeposit" border="surround" placeholder="请输入开户银行"></u--input>
				</u-form-item>
				<u-form-item label="银行账号" prop="bankAccount" ref="item1">
					<u--input v-model="model1.bankAccount" border="surround" placeholder="请输入银行账号"></u--input>
				</u-form-item>
				<u-form-item label="客户税号" prop="clientDutyNum" ref="item1">
					<u--input v-model="model1.clientDutyNum" border="surround" placeholder="请输入客户税号"></u--input>
				</u-form-item>
				<u-form-item label="备注" prop="remark" ref="item1">
					<u--textarea v-model="model1.remark" border="surround" placeholder="请输入备注"></u--textarea>
				</u-form-item>
			</u--form>
		</view>
		<view style="height: 200rpx;"></view>
		<view class="footer">
			<u-button type="primary" text="编辑" @click="customerManagementEditClick" v-if="model1.id"></u-button>
			<u-button type="primary" text="保存" @click="customerManagementClick" v-else></u-button>
		</view>
		<u-datetime-picker :show="show" v-model="value1" mode="date" @confirm="confirm" @cancel="cancel"
			:closeOnClickOverlay="true"></u-datetime-picker>
	</view>
</template>

<script>
	import {
		id
	} from 'element-plus/es/locale';
	export default {
		data() {
			return {
				model1: {
					id: '',
					bankAccount: "",
					bankOfDeposit: "",
					clientBirthday: "",
					clientCode: "",
					clientDutyNum: "",
					clientName: "",
					contactAddress: "",
					contactPerson: "",
					contactPhone: "",
					email: "",
					remark: "",
					socialAccount: ""
				},
				rules: {
					'clientName': {
						type: 'string',
						required: true,
						message: '请输入供应商名称',
						trigger: ['blur', 'change']
					},
					'clientCode': {
						type: 'string',
						required: true,
						message: '请输入供应商编号',
						trigger: ['blur', 'change']
					}
				},
				pageNo: 1,
				pageSize: 100,
				show: false,
				value1: Number(new Date()),
			}
		},
		onReady() {
			//如果需要兼容微信小程序，并且校验规则中含有方法等，只能通过setRules方法设置规则。
			this.$refs.uForm.setRules(this.rules)
		},
		/**
		 * 生命周期函数--监听页面加载
		 */
		onLoad(options) {
			if (!this.$u.test.isEmpty(options.item)) {
				const item = JSON.parse(decodeURIComponent(options.item));
				console.log(item)
				this.model1 = {
					id: item.id,
					bankAccount: item.bankAccount,
					bankOfDeposit: item.bankOfDeposit,
					clientBirthday: item.clientBirthday,
					clientCode: item.clientCode,
					clientDutyNum: item.clientDutyNum,
					clientName: item.clientName,
					contactAddress: item.contactAddress,
					contactPerson: item.contactPerson,
					contactPhone: item.contactPhone,
					email: item.email,
					remark: item.remark,
					socialAccount: item.socialAccount
				}
			} else {
				this.fin_kh_bill_no()
			}

		},
		onShow() {
			// this.isLogin = checkLogin()
			// if (!this.isLogin) {
			// 	this.isloginBind()
			// 	return false
			// }


		},
		methods: {
			confirm(e) {
				this.model1.clientBirthday = this.$u.timeFormat(e.value, 'yyyy-mm-dd');
				this.show = false
			},
			//fin_kh_bill_no客户编号
			fin_kh_bill_no() {
				this.$apis.fin_kh_bill_no().then(res => {
					this.model1.clientCode = res.result
				})
			},
			cancel() {
				this.show = false
			},
			customerManagementClick() {
				let form = {
					bankAccount: this.model1.bankAccount,
					bankOfDeposit: this.model1.bankOfDeposit,
					clientBirthday: this.model1.clientBirthday,
					clientCode: this.model1.clientCode,
					clientDutyNum: this.model1.clientDutyNum,
					clientName: this.model1.clientName,
					contactAddress: this.model1.contactAddress,
					contactPerson: this.model1.contactPerson,
					contactPhone: this.model1.contactPhone,
					email: this.model1.email,
					remark: this.model1.remark,
					socialAccount: this.model1.socialAccount
				}
				console.log(form)
				this.$refs.uForm.validate().then(res => {
					this.$apis.customerManagementAdd(form).then(res => {
						if (res.code == 200) {
							this.$u.toast(res.result)
							setTimeout(() => {
								uni.navigateBack()
							}, 1000);
						}
					})
				}).catch(errors => {})
			},
			customerManagementEditClick() {
				let form = {
					id: this.model1.id,
					bankAccount: this.model1.bankAccount,
					bankOfDeposit: this.model1.bankOfDeposit,
					clientBirthday: this.model1.clientBirthday,
					clientCode: this.model1.clientCode,
					clientDutyNum: this.model1.clientDutyNum,
					clientName: this.model1.clientName,
					contactAddress: this.model1.contactAddress,
					contactPerson: this.model1.contactPerson,
					contactPhone: this.model1.contactPhone,
					email: this.model1.email,
					remark: this.model1.remark,
					socialAccount: this.model1.socialAccount
				}
				console.log(form)
				this.$refs.uForm.validate().then(res => {
					this.$apis.customerManagementEdit(form).then(res => {
						if (res.code == 200) {
							this.$u.toast(res.result)
							setTimeout(() => {
								uni.navigateBack()
							}, 1000);
						}
					})
				}).catch(errors => {})
			}
		},


	}
</script>
<style>
	page {
		background-color: #F5F5F5;
	}
</style>
<style lang="scss" scoped>
	.tagoul {
		display: flex;
		background-color: #f5f5f5;
	}

	.tagclass {
		height: 400px;
		overflow: scroll;
		list-style: none;
	}

	.icon {
		border: 1px solid #E0E0E0;
		padding: 8rpx 20rpx;
		border-radius: 10rpx;
	}

	.add {
		background-color: #3247D3;
		padding: 8rpx 20rpx;
		border-radius: 10rpx;
		color: #fff;
	}

	.cl-status {
		color: #6A6A6A;
	}

	.pore {
		position: relative;
	}

	.popBox {
		position: relative;

		.btns {
			position: absolute;
			bottom: 30rpx;
			right: 30rpx;
			left: 30rpx;

			.confirm {
				padding: 8rpx 30rpx;
				border-radius: 10rpx;
				background-color: #3247D3;
				color: #fff;
			}
		}
	}

	.border-top {
		border-top: 1px solid #F8F8F8;
	}

	.number {
		background-color: #3247D3;
		color: #fff;
		font-size: 22rpx;
		padding: 4rpx 10rpx;
		border-radius: 8rpx;
	}

	.footer {
		position: fixed;
		bottom: 0;
		background-color: #fff;
		width: 100%;
		padding: 30rpx;
		z-index: 999;
	}

	.cl-h1 {
		color: #6fbcff
	}
</style>